"""### 5.3 【资源模板】Resource Template 服务端开发"""

from mcp.server import FastMCP

#定义 Resource template 资源模板实例类
mcp = FastMCP("Resource Template MCP Server")
#定义资源
@mcp.resource(
    uri = "books://query/{book_id}",
    name = "query_book",
    description = "查询图书信息",
    mime_type = "application/json",
)
def query_book_resource_template(book_id:str):
    """
    模拟查询图书信息
    :param book_id: 图书ID
    """
    print("==请求资源：query_book_resource_template")
    return {
        "book_id":book_id,
        "title":"Python Programming",
        "author":"John Smith",
        "year":2023
    }
if __name__ == "__main__":
    print("Resource Template资源 ---> MCP Server is running...")
    mcp.run(transport="sse")